package com.example.ymm.modules1.service.impl.sys.iot;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.sys.iot.IotShelf;
import com.example.ymm.modules1.mapper.my.sys.IotShelfMapper;
import com.example.ymm.modules1.query.sys.iot.IotShelfQueryCriteria;
import com.example.ymm.modules1.service.sys.iot.IotShelfService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DS("slave2")
@Slf4j
public class IotShelfServiceImpl extends BaseServiceImpl<IotShelfMapper, IotShelf> implements IotShelfService {



    @Override
    public TableList<IotShelf> list(IotShelfQueryCriteria criteria, YmPageDto pageDto) {
        IPage<IotShelf> page = new Page<IotShelf>(pageDto.getPage(),pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(IotShelf.class, criteria);
        predicate.orderByAsc("sort");
        baseMapper.selectPage(page, predicate);
        TableList<IotShelf> tableList=new TableList(page);
        return tableList;
    }
    
    public List<IotShelf> queryAll(IotShelfQueryCriteria criteria) {
        List<IotShelf> result =baseMapper.selectList(QueryHelpPlus.getPredicate(IotShelf.class, criteria));
        return result;
    }

    @Override
    public IotShelf getShelfName(String shelfName) {
        IotShelfQueryCriteria criteria = new IotShelfQueryCriteria();
        criteria.setShelfName(shelfName);
        List<IotShelf> result = queryAll(criteria);
        if(result.size()>0){
            return result.get(0);
        }
        return null;
    }
}
